////////////////////////////////////////////////////////////////////////////
//
//  Crytek Engine Source File.
//  Copyright (C), Crytek Studios, 2005.
// -------------------------------------------------------------------------
//  File name:   TimeOfDayDialog.h
//  Version:     v1.00
//  Created:     12/3/2002 by Timur.
//  Compilers:   Visual C++ 7.0
//  Description: 
// -------------------------------------------------------------------------
//  History:
//
////////////////////////////////////////////////////////////////////////////

#ifndef __TimeOfDayDialog_h__
#define __TimeOfDayDialog_h__

#include "ToolbarDialog.h"
#include "Controls/SliderCtrlEx.h"
#include "Controls/PropertyCtrl.h"
#include "Controls/TimelineCtrl.h"
#include "Controls/TimeOfDayEdit.h"

struct ISplineInterpolator;

//////////////////////////////////////////////////////////////////////////

class CSplineCtrl;
class CColorGradientCtrl;
class CEnvironmentTimelineSlider;
class CHDRPane;
//////////////////////////////////////////////////////////////////////////
// Window that holds effector info.
//////////////////////////////////////////////////////////////////////////
class CTimeOfDayDialog : public CXTPFrameWnd, public IEditorNotifyListener
{
	DECLARE_DYNCREATE(CTimeOfDayDialog)
public:
	static const char* ClassName() { return "EnvironmentEditorFrame"; }

	CTimeOfDayDialog();
	~CTimeOfDayDialog();

	static void RegisterViewClass();
	static void UpdateValues();
	bool				IsPlaying(){ return m_bAnimation; }

protected:
	DECLARE_MESSAGE_MAP()

	virtual void PostNcDestroy();
	afx_msg void OnSplineRClick( UINT nID, NMHDR* pNMHDR, LRESULT* lpResult );
	afx_msg void OnBeforeSplineChange( UINT nID, NMHDR* pNMHDR, LRESULT* lpResult );
	afx_msg void OnSplineChange( UINT nID, NMHDR* pNMHDR, LRESULT* lpResult );
	afx_msg void OnSplineCmd( UINT nCmd );
	afx_msg LRESULT OnTaskPanelNotify( WPARAM wParam, LPARAM lParam );
	afx_msg LRESULT OnDockingPaneNotify( WPARAM wParam, LPARAM lParam );
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnClose();
	afx_msg void OnDestroy();

	afx_msg void OnPlayAnim();
	afx_msg void OnUpdatePlayAnim( CCmdUI* pCmdUI );
	afx_msg void OnRecord();
	afx_msg void OnUpdateRecord( CCmdUI* pCmdUI );
	afx_msg void OnPlayAnimFrom0();
	afx_msg void OnUpdatePlayAnimFrom0( CCmdUI* pCmdUI );
	afx_msg void OnGotoMinus1();
	afx_msg void OnGoto0();
	afx_msg void OnGoto1();
	afx_msg void OnChangeCurrentTime( UINT nID );
	afx_msg void OnChangeTimeAnimSpeed();
	afx_msg void OnToggleBasicAdvancedProperties();

	afx_msg void OnImport();
	afx_msg void OnExport();
	afx_msg void OnExpandAll();
	afx_msg void OnResetToDefaultValues();
	afx_msg void OnCollapseAll();

	afx_msg void OnHold();
	afx_msg void OnFetch();
	afx_msg void OnUndo();
	afx_msg void OnRedo();

	afx_msg void OnPropertySelected(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnTimelineCtrlChange(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnSplineCtrlScrollZoom(NMHDR* pNMHDR, LRESULT* pResult);

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual void RecalcLayout( BOOL bNotify = TRUE );

	bool Init();
	bool CreatePanes();
	static bool RegisterWindowClass();
	void OnUpdateProperties( IVariable *var );

	void CreateProperties();

	void SetTime( float fTime,bool bOnlyUpdateUI=false,bool bNoPropertiesUpdate=false );
	void SetTimeRange( float fTimeStart,float fTimeEnd,float fSpeed );
	float GetTime() const;

	void RefreshPropertiesValues( bool bSetTime=true );
	void ResetSpline( IVariable* var );

	IVariable * FindVariable(const char *name) const;
	
	//////////////////////////////////////////////////////////////////////////
	// IEditorNotifyListener
	//////////////////////////////////////////////////////////////////////////
	virtual void OnEditorNotifyEvent( EEditorNotifyEvent event );
	//////////////////////////////////////////////////////////////////////////
private:
	CXTPToolBar m_wndToolBar;
	CXTPToolBar m_splineToolBar;
	CXTPTaskPanel m_wndTaskPanel;

	CXTPDockingPaneManager	m_paneManager;    

	std::auto_ptr<CPropertyCtrl> m_pPropsCtrl;
	std::auto_ptr<CEnvironmentTimelineSlider> m_pTimelineSlider;
	std::auto_ptr<CHDRPane> m_pHDRPane;
	CVarBlockPtr m_pVars;

	CTimelineCtrl m_timelineCtrl;
	bool m_bAnimation;
	bool m_bPlayFrom0;
	bool m_bRecording;
	bool m_bShowOnlyBasicProperties;

	int m_splineCtrlHeight;

	CTimeOfDayEdit m_timeEdit;
	CButton m_forceUpdateCheck;

	CTimeOfDayEdit m_timeEditStart;
	CTimeOfDayEdit m_timeEditEnd;

	CNumberCtrl m_timeAnimSpeedCtrl;

	static CTimeOfDayDialog* m_pInstance;

	CSplineCtrlEx *m_pSplineCtrl;
	CColorGradientCtrl *m_pColorGradientCtrl;

	// used to show only the basic properties in the property grid
	std::set<CString> m_basicPropertyDisplayNames;
	friend CEnvironmentTimelineSlider;
	friend CHDRPane;
};

#endif // __TimeOfDayDialog_h__
